<?php
// +---------------------------------------------------------------------------+
// | This file is part of the KnowledgebasePublisher package                   |
// | KnowledgebasePublisher - web based knowledgebase publisher tool           |
// |                                                                           |
// | Author:  Evgeny Leontev <eleontev@gmail.com>                              |
// | Copyright (c) 2005 Evgeny Leontev                                         |
// |                                                                           |
// | For the full copyright and license information, please view the LICENSE   |
// | file that was distributed with this source code.                          |
// +---------------------------------------------------------------------------+

require_once 'eleontev/Util/Replacer.php';

class KBClientView_success_go extends KBClientView_common
{
	
	var $timeout = 3000;
	
	
	
	function &execute(&$manager) {
		
		$tpl = &new tplTemplatez($this->template_dir . 'success_go.html');
		
		$this->controller->arg_separator = '&';
		$msg_key = $this->controller->getRequestVar('msg');
		$view_id = $this->getViewId($msg_key);
		$msg_id = $this->getMsgId($msg_key);
		$url = $this->_getLink($view_id, $this->category_id, $this->entry_id, $msg_id);
		
		$tpl->tplAssign('go_url', $url);
		$tpl->tplAssign('timeout', $this->getTimeout($msg_key));		
		$tpl->tplAssign('msg', $this->getActionMsg());
		$tpl->tplAssign($this->css);
		
		$r = new Replacer();
		$msg = $r->parse($this->msg['redirect_msg'], array('go_url'=>$url));
		
		$tpl->tplAssign('redirect_msg', $msg);

		
		$tpl->tplParse($this->msg);
		return $tpl->tplPrint(1);			
	}
	
	
/*
	function getMsgKeysValues() {
		
		$msg_key['comment_posted']['return'] = 
		$msg_key['comment_posted']['delay']  = 
		
		$msg_key['']['return'] = '';
		$msg_key['']['delay']  = 1;
		
	
	}
*/
	
	
	// where to return after message 
	function getViewId($key) {
		$view = array('comment_posted' => 'entry',
		              'comment_wait'   => 'entry',
					  'entry_sent'     => false,
					  'friend_sent'    => 'entry',
					  'password_sent'  => 'login',
					  'registration_confirmed' => 'login');
					  
		return (isset($view[$key])) ? $view[$key] : false;
	}
	
	
	// what msg to display after message 
	function getMsgId($key) {
		//$view = array('confirmation_sent' => 'confirmation_sent');
		$view = array();
					  
		return (isset($view[$key])) ? $view[$key] : false;
	}	
	
	
	// set js delay time on after action screen
	// for keys use 0.5, 1, 2 so on 
	// it will set delay time = $this->delay_time*key
	function getTimeout($key) {
		$multilplier = array('comment_posted' 				=> 1,
		            		 'comment_wait'  				=> 2,
							 'entry_sent'	 				=> 3,
							 'registration_not_confirmed'	=> 3,
					         'registration_confirmed'  		=> 2,
					         'confirmation_sent'			=> 3,
							 'confirmation_not_sent'		=> 3);
					  
		return (isset($multilplier[$key])) ? $this->timeout*$multilplier[$key] : $this->timeout;
	}
}
?>